package org.bigjava.buff.goods.web.listener;

import org.bigjava.buff.goods.mapper.GoodsMapper;
import org.bigjava.buff.user.mapper.DealMapper;
import org.bigjava.buff.user.service.DealService;
import org.bigjava.buff.user.service.impl.DealServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.List;

public class IndexDataListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent servletContextEvent) {

        ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        DealService dealService = app.getBean("dealServiceImpl", DealServiceImpl.class);

        List list = dealService.getNewDeal();
        for (Object o : list) {
            System.out.println(o);
        }
        servletContextEvent.getServletContext().setAttribute("indexList", list);

    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
